package de.baumann.browser.fragments.duobao

import android.view.View
import de.baumann.browser.R
import de.baumann.browser.activitys.duobao.DuoBaoWanFaGuiZeActivity
import de.baumann.browser.activitys.duobao.JieXiaoDetailActivity
import de.baumann.browser.adapter.JieXiaoAdapter
import de.baumann.browser.api.net.vo.duobao.JieXiao
import de.baumann.browser.api.net.vo.duobao.WFGZ
import de.baumann.browser.base.BaseOdinFragment
import de.baumann.browser.iview.IJieXiaoListView
import de.baumann.browser.present.duobao.JieXiaoListPresenter
import kotlinx.android.synthetic.main.fragment_duo_bao_jie_xiao.*

class DuoBaoJieXiaoFragment : BaseOdinFragment<IJieXiaoListView, JieXiaoListPresenter>(), IJieXiaoListView {

    companion object {
        val instance: DuoBaoJieXiaoFragment by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            DuoBaoJieXiaoFragment()
        }
    }

    private lateinit var jieXiaoAdapter: JieXiaoAdapter

    override fun getLayout(): Int {
        return R.layout.fragment_duo_bao_jie_xiao
    }

    override fun initView(view: View) {
        jiexiaoBack.setOnClickListener {
            activity?.finish()
        }
        jieXiaoAdapter = JieXiaoAdapter()
        jiexiaoList.adapter = jieXiaoAdapter
        jieXiaoAdapter.setOnItemClickListener { adapter, view, position ->
            val jiexiao = jieXiaoAdapter.getItem(position)
            JieXiaoDetailActivity.startJieXiaoDetailActivity(mContext,jiexiao!!.activityId.toString(),jiexiao.phaseNum)
        }

        jxwfgz.setOnClickListener {
            DuoBaoWanFaGuiZeActivity.startDuoBaoWanFaGuiZeActivity(mContext)
        }

    }

    override fun initData() {
        getPresenter().getJieXiaoList()
    }

    override fun createPresenter(): JieXiaoListPresenter? {
        return JieXiaoListPresenter()
    }

    override fun createView(): IJieXiaoListView? {
        return this
    }

    override fun setList(list: List<JieXiao>?) {
        jieXiaoAdapter.setNewData(list)
    }

}